package com.mt.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * @author Wang
 * @Description 性别枚举
 * @date 2021/1/14-14:54
 */
@Getter
public enum Sex {

    DEFAULT(0,"未填写"),
    MAN(1, "男"),
    WOMEN(2, "女");

    @EnumValue
    private Integer code;
    @JsonValue
    private String sex;

    Sex(Integer code, String sex) {
        this.code = code;
        this.sex = sex;
    }

    public static int sexCode(Sex sex) {
        for (Sex s :Sex.values()){
            if (s.getSex()==sex.getSex()) {
                return s.getCode();
            }
        }
        return -1;
    }

    public static String sexName(Sex sex) {
        for (Sex s :Sex.values()){
            if (s.getCode().equals(sex.getCode())) {
                return s.getSex();
            }
        }
        return null;
    }
}
